home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume5 / rsed < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  37.6 KB

  1. Path: xanth!nic.MR.NET!hal!ncoast!allbery
  2. From: doug@letni.UUCP (Doug Davis at letni.UUCP)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i082: rsed -- simple in-core editor
  5. Message-ID: <00001977-881112081327-346@letni.UUCP>
  6. Date: 14 Dec 88 03:01:09 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: doug@letni.UUCP (Doug Davis at letni.UUCP)
  9. Lines: 1477
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. Posting-number: Volume 5, Issue 82
  13. Submitted-by: "Doug Davis at letni.UUCP" <doug@letni.UUCP>
  14. Archive-name: rsed
  15.  
  16. The attached shar file is source of a simple user-friendly(?) text file
  17. editor that I was commissioned to write for a bunch of computer illiterate's
  18. to edit mail messages.  The editor makes use of an in-memory linked list
  19. for storing each line, this gives it the ability to edit any size text
  20. file that a machine has user process space for.  I'm sending it to
  21. you to post, mostly because it shows a good simple example of using a linked
  22. list, as well as in the hopes that someone will take it further along 
  23. the evolutionary scale, and perhaps turn it into a real editor.
  24.  
  25. As usual I will gladly accept all of patches for suggested changes
  26. or porting problems. Flames however will cheerfully be ignored.
  27.  
  28. Doug Davis
  29. Lawnet
  30. 1030 Pleasent Valley Lane
  31. Arlington Texas 76015
  32. (817)-467-3740
  33.  
  34. { killer!texbell, sys1.tandy.com, lawnet, motown!sys1 } letni!doug
  35.  
  36.  
  37. #! /bin/sh
  38. # This is a shell archive.  Remove anything before this line, then unpack
  39. # it by saving it into a file and typing "sh file".  To overwrite existing
  40. # files, type "sh file -c".  You can also feed this as standard input via
  41. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  42. # will see the following message at the end:
  43. #        "End of archive 1 (of 1)."
  44. # Contents:  README rsedhelp Makefile defs.h externs.h command.c edit.c
  45. #   find.c globals.c input.c main.c mem.c multi.c stuff.c
  46. # Wrapped by doug@letni on Mon Dec 12 02:07:29 1988
  47. PATH=/bin:/usr/bin:/usr/local/bin:/usr/ucb ; export PATH
  48. if test -f 'README' -a "${1}" != "-c" ; then 
  49.   echo shar: Will not clobber existing file \"'README'\"
  50. else
  51. echo shar: Extracting \"'README'\" \(3961 characters\)
  52. sed "s/^X//" >'README' <<'END_OF_FILE'
  53. X
  54. Real Simple Ed 
  55. X
  56. Rsed is a real simple editor program designed for people who are calling
  57. into a machine to be able to edit files on a variaty of differen't 
  58. terminals and/or computers WITHOUT haveing to learn an editor.  Rsed
  59. is very easy to use and tries to be as "user friendly" as possable.
  60. X
  61. Defines:
  62. WSEDHELP          Where the help file resieds.
  63. MAXREPLACE        malloc size for the replacement string
  64. BEGINDOTS         size of file to warrent nifty-userfriendly dots to show
  65. X                  that we are doing something.
  66. X
  67. Options:
  68. X    -a ##    load file and append after line ##
  69. X    -w         write the file out when you quit the editor (silent)
  70. X    -D        debug (used for fiddling with the linked list)
  71. X
  72. X
  73. Porting:
  74. X    rsed usese curses just for turning off echo and setting crmod, 
  75. X    if you don't want to fool with that, or don't have curses you will
  76. X    have to fix up your own terminal handler. The following are the
  77. X    function calls to worry about.
  78. X        savetty() save the current modes of the terminal for later recall
  79. X        initscr() sets up curses.
  80. X        crmode()  puts the terminal into One Charicter At A Time mode.
  81. X        resetty() restores the previously saved tty information.
  82. X    
  83. X    rsed also uses getopt() most later version unix's have this, if
  84. X    yours does not, a public domain version of it is available thru
  85. X    comp.sources.unix.
  86. X    
  87. X    Othewise rsed has been known to compile without changes on 4.1 BSD (vax),
  88. X    4.2 BSD (vax) 4.3 BSD (vax), Ultrix (vax) sco (%d86) micro, Tandy 6000,
  89. X    Masscomp, NCR tower, ATT 3b2 and a logic processes Mpulse. So it ought
  90. X    to compile on yours.  If your compiler can't handle macros you will
  91. X    need to work on the RANGE marco in multi.c.  Otherwise
  92. X    please let me know of any problems and may the source be with you %s.
  93. X
  94. X
  95. Author:
  96. X    Douglas L. Davis
  97. X    (Lawnet, Texas R&D office)
  98. X    1030 Pleasent Valley Lane
  99. X    Arlington Texas  76015
  100. X    (817)-467-3740
  101. X    { sys1 || texbell || lawnet }!letni!doug
  102. X    
  103. X
  104. XFunction call        Description
  105. main            Main routine, parses args, calls edit.
  106. add             adds a char array below line number specified.
  107. append          asks user for lines to add().
  108. boom            debug sigint routine.
  109. change          asks user for a replacement line.
  110. clear_stuff     frees the entire linked list.
  111. command         does the command prompting
  112. edit            if nessasary creates the file, then loads it.
  113. find            returns a line with a pre-specified string
  114. getline         returns a LINE pointer for the specified line number.
  115. getlineno       gets a line number from the tty.
  116. getstring       gets a string from the tty.
  117. global_replace  replaces a specified string with another full file.
  118. go_fish         asks user for a search string then calls find with it.
  119. go_global       asks user for a search string and a replacement string.
  120. help            concatinate the rsedhelp file.
  121. insert          asks user for a line.
  122. loadem          reads a file into the editor buffer.
  123. makenum         convert a string to a numeric entry.
  124. printline       prints a line out of the editor.
  125. replace         replace the text of a specified line with a user buf
  126. reset_find      clears the global search stuff.
  127. saveem          saves the editor buf to a file.
  128. setfind         sets up the global search stuff.
  129. setline         set the current line to a specified line number.
  130. srch_n_replace  do a search / replace within a (LINE *) struct
  131. srchrep         user interface for srch_n_replace.
  132. strappend       like strcat() but returns then end of it's string.
  133. strindex        returns a pointer to a string found in another string.
  134. subtract        removes a spacified line from the buffer.
  135. yesno           asks for a yes or no answer from the user.
  136. multi_print     ask for starting line / ending line then for()'s printline()
  137. multi_delete    ask for starting line / ending line then for()'s subtract()
  138. multi_change    ask for starting line / ending line then for()'s change()
  139. END_OF_FILE
  140. if test 3961 -ne `wc -c <'README'`; then
  141.     echo shar: \"'README'\" unpacked with wrong size!
  142. fi
  143. # end of 'README'
  144. fi
  145. if test -f 'rsedhelp' -a "${1}" != "-c" ; then 
  146.   echo shar: Will not clobber existing file \"'rsedhelp'\"
  147. else
  148. echo shar: Extracting \"'rsedhelp'\" \(1086 characters\)
  149. sed "s/^X//" >'rsedhelp' <<'END_OF_FILE'
  150. X
  151. X  Keys             Action
  152. X ------          ---------
  153. X [0-9]  .........change the current line.
  154. X   $    .........go to the bottom of the file.
  155. X   ^    .........go to the top of the file.
  156. X+ or ;  .........advance to the next line.
  157. X   -    .........backup to the previous line.
  158. X   a    .........append text after the current line.
  159. X   c    .........change (i.e. replace) the current line.
  160. X   d    .........delete (i.e. remove) the current line.
  161. f or /  .........find and advance to a line with a specified string.
  162. X   g    .........global replacement (entire file) of a string with another.
  163. X   i    .........insert text before the current line.
  164. X   n    .........advance to the next occurence of a string (re: f option)
  165. X   p    .........print (i.e. display) the current line.
  166. X   q    .........quit the editor.
  167. X   s    .........search and replace a string on the current line.
  168. X   w    .........write out all changes.
  169. X   P    .........asks for and then prints a range of lines.
  170. X   ?    .........display this file.
  171. X
  172. Note: input(s) can be ended or aborted by entering a '.' on a line by itself.
  173. END_OF_FILE
  174. if test 1086 -ne `wc -c <'rsedhelp'`; then
  175.     echo shar: \"'rsedhelp'\" unpacked with wrong size!
  176. fi
  177. # end of 'rsedhelp'
  178. fi
  179. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  180.   echo shar: Will not clobber existing file \"'Makefile'\"
  181. else
  182. echo shar: Extracting \"'Makefile'\" \(960 characters\)
  183. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  184. X# in an '86 environment this better be compiled in large model
  185. SHELL=/bin/sh
  186. X
  187. X# defines for curses that needs termcap BSD,  xenix,  etc....
  188. X# CURSNAME  = -lcurses -ltermlib
  189. X# CURSNAME    = -lcurses -ltermcap
  190. X# defines for sysV curses needs cbreak() function call.
  191. X# if yours has crmode() instead, you will have to hack defs.h
  192. X# CURSNAME    = -lcurses 
  193. X
  194. X# if your machine has strchr
  195. X# DEFINES=-DSTRCHR=strchr
  196. X# if your machine has index / rindex
  197. X# DEFINES=-DSTRCHR=index
  198. X
  199. X# for 286 uncomment the line below
  200. X# CFLAGS    =    -O -AL $(DEFINES)
  201. X# LDFLAGS =    -AL -i
  202. X# for most other systems
  203. X# CFLAGS    =    -O $(DEFINES)
  204. X# LDFLAGS    =    -n
  205. OBJECTS =    globals.o main.o mem.o command.o edit.o input.o stuff.o \
  206. X        find.o multi.o
  207. CC=/bin/cc
  208. X
  209. all: rsed
  210. X
  211. rsed:    ${OBJECTS}
  212. X        $(CC) ${LDFLAGS} ${OBJECTS} -o rsed $(CURSNAME)
  213. X
  214. tags: *.h *.c
  215. X    ctags *.h *.c
  216. X
  217. shar:
  218. X    shar -n 1 -e 1 -t 'Now read the README file and edit the Makefile for your system' \
  219. X        README rsedhelp Makefile *.h *.c > rsed.shar
  220. END_OF_FILE
  221. if test 960 -ne `wc -c <'Makefile'`; then
  222.     echo shar: \"'Makefile'\" unpacked with wrong size!
  223. fi
  224. # end of 'Makefile'
  225. fi
  226. if test -f 'defs.h' -a "${1}" != "-c" ; then 
  227.   echo shar: Will not clobber existing file \"'defs.h'\"
  228. else
  229. echo shar: Extracting \"'defs.h'\" \(984 characters\)
  230. sed "s/^X//" >'defs.h' <<'END_OF_FILE'
  231. X/*
  232. X * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  233. X *  You are free to modify, hack, fold, spindle, or mutlate this code in
  234. X *  any maner provided you give credit where credit is due and don't pretend
  235. X *  you wrote it.
  236. X *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  237. X *  in copyright law that you will never ever forget.
  238. X */
  239. X#include <sys/types.h>
  240. X#include <signal.h>
  241. X#include <fcntl.h>
  242. X#include <ctype.h>
  243. X#include <sys/stat.h>
  244. X#include <stdio.h>
  245. X#include <errno.h>
  246. X#include "curses.h"
  247. X
  248. X#define WSEDHELP    "/usr/lib/rsedhelp";
  249. X#define    MAXREPLACE    4096 /* biggest tmp line size for global replacement */
  250. X#define    BEGINDOTS    24L * 1024L /* size of file to warrent dots to show
  251. X                    that we are doing something */
  252. X
  253. typedef struct line {
  254. X    struct line *previous;
  255. X    struct line *next;
  256. X    char text[1]; /* has to be end */
  257. X} LINE;
  258. X
  259. X#ifndef MSDOS
  260. X    #ifdef CBREAK
  261. X    #define One_Char()    crmode();
  262. X    #else
  263. X    #define One_Char()    cbreak();
  264. X    #endif
  265. X#endif MSDOS
  266. END_OF_FILE
  267. if test 984 -ne `wc -c <'defs.h'`; then
  268.     echo shar: \"'defs.h'\" unpacked with wrong size!
  269. fi
  270. # end of 'defs.h'
  271. fi
  272. if test -f 'externs.h' -a "${1}" != "-c" ; then 
  273.   echo shar: Will not clobber existing file \"'externs.h'\"
  274. else
  275. echo shar: Extracting \"'externs.h'\" \(1116 characters\)
  276. sed "s/^X//" >'externs.h' <<'END_OF_FILE'
  277. X
  278. X/*
  279. X * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  280. X *  You are free to modify, hack, fold, spindle, or mutlate this code in
  281. X *  any maner provided you give credit where credit is due and don't pretend
  282. X *  you wrote it.
  283. X *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  284. X *  in copyright law that you will never ever forget.
  285. X */
  286. extern    FILE    *EditFile;
  287. extern    LINE    *current;
  288. extern    LINE    *find_work;
  289. extern    LINE    *getline();
  290. extern    LINE    *l_end;
  291. extern    LINE    *l_start;
  292. extern    LINE    *setline();
  293. extern    char    *Bottom;
  294. extern    char    *Eof;
  295. extern    char    *HelpName;
  296. extern    char    *Progname;
  297. extern    char    *STRCHR();
  298. extern    char    *Top;
  299. extern    char    *find_string;
  300. extern    char    *getstring();
  301. extern    char    *malloc();
  302. extern    char    *strappend();
  303. extern    char    *strindex();
  304. extern    char    Dots;
  305. extern    char    WriteOnQuit;
  306. extern    char    buf[BUFSIZ];
  307. extern    char    yesno();
  308. extern    int    Debug;
  309. extern    int    errno;
  310. extern    int    getopt();
  311. extern    long    CurrentLine;
  312. extern    long    NumberLines;
  313. extern    long    atol();
  314. extern    long    find();
  315. extern    long    find_line;
  316. extern    long    getlineno();
  317. extern    long    loadem();
  318. extern    long    makenum();
  319. END_OF_FILE
  320. if test 1116 -ne `wc -c <'externs.h'`; then
  321.     echo shar: \"'externs.h'\" unpacked with wrong size!
  322. fi
  323. # end of 'externs.h'
  324. fi
  325. if test -f 'command.c' -a "${1}" != "-c" ; then 
  326.   echo shar: Will not clobber existing file \"'command.c'\"
  327. else
  328. echo shar: Extracting \"'command.c'\" \(4136 characters\)
  329. sed "s/^X//" >'command.c' <<'END_OF_FILE'
  330. X
  331. X/*
  332. X * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  333. X *  You are free to modify, hack, fold, spindle, or mutlate this code in
  334. X *  any maner provided you give credit where credit is due and don't pretend
  335. X *  you wrote it.
  336. X *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  337. X *  in copyright law that you will never ever forget.
  338. X */
  339. X#include "defs.h"
  340. X#include "externs.h"
  341. X
  342. command(file, sline)
  343. char *file;
  344. char *sline;
  345. X{
  346. X    char c;
  347. X    long start;
  348. X    char changed='N';
  349. X    if (*sline != '\0') {
  350. X        start=makenum(sline);
  351. X        fputs("appending ", stdout);
  352. X        if (start >= NumberLines) 
  353. X            fputs("to the bottom", stdout);
  354. X        else 
  355. X            printf("below line %ld", start);
  356. X        puts(", enter text now:");
  357. X        append(start <= NumberLines ? start : NumberLines);
  358. X        start=NumberLines;
  359. X    } else
  360. X        start = 1L;
  361. X    
  362. X    if (NumberLines > 0L)
  363. X        setline(start);
  364. X    for (;;) {
  365. X        if (NumberLines < 1L || CurrentLine < 1L) {
  366. X            puts("Buffer empty, begin entering new text.");
  367. X            append(0L);
  368. X            continue;
  369. X        }
  370. X        if (Debug) {
  371. X            printf("address             l_start: 0x%lx\n",
  372. X                l_start);
  373. X            printf("address             current: 0x%lx\n",
  374. X                current);
  375. X            printf("address               l_end: 0x%lx\n",
  376. X                l_end);
  377. X            printf("address l_start -> previous: 0x%lx\n", 
  378. X                l_start->previous);
  379. X            printf("address       l_end -> next: 0x%lx\n",
  380. X                l_end->next);
  381. X        }
  382. X        printf("Line %ld>", CurrentLine);
  383. X#ifdef MSDOS
  384. X        c=getch();
  385. X#else 
  386. X        c=getchar();
  387. X#endif MSDOS
  388. X        switch(c) {
  389. X            case '0':
  390. X            case '1':
  391. X            case '2':
  392. X            case '3':
  393. X            case '4':
  394. X            case '5':
  395. X            case '6':
  396. X            case '7':
  397. X            case '8':
  398. X            case '9':
  399. X                fputs("Enter new line :", stdout);
  400. X                getstring(buf, 10, c);
  401. X                if ((start=makenum(buf)) > 0L && 
  402. X                        start <= NumberLines) {
  403. X                    if (setline(start) == (LINE *) NULL) 
  404. X                        puts("Sorry..");
  405. X                }
  406. X                break;
  407. X            case '+':
  408. X            case ';':
  409. X                putchar('\n');
  410. X                if (CurrentLine < NumberLines) {
  411. X                    CurrentLine++;
  412. X                    printline(CurrentLine);
  413. X                } else
  414. X                    puts(Bottom);
  415. X                break;
  416. X            case '-':
  417. X                putchar('\n');
  418. X                if (CurrentLine > 1) {
  419. X                    CurrentLine--;
  420. X                    printline(CurrentLine);
  421. X                } else 
  422. X                    puts(Top);
  423. X                break;
  424. X            case '$':
  425. X                putchar('\n');
  426. X                CurrentLine = NumberLines;
  427. X                setline(CurrentLine);
  428. X                puts(Bottom);
  429. X                break;
  430. X            case '^':
  431. X                putchar('\n');
  432. X                CurrentLine = 1L;
  433. X                setline(CurrentLine);
  434. X                puts(Top);
  435. X                break;
  436. X            case 'C':
  437. X                puts("Change lines.");
  438. X                multi_change();
  439. X                changed = 'Y';
  440. X                break;
  441. X            case 'D':
  442. X                puts("Delete lines.");
  443. X                multi_delete();
  444. X                changed = 'Y';
  445. X                break;
  446. X            case 'P':
  447. X                puts("Print.");
  448. X                multi_print();
  449. X                break;
  450. X            case 'a':
  451. X                printf("Appending after line # %ld\n", CurrentLine);
  452. X                append(CurrentLine);
  453. X                changed = 'Y';
  454. X                break;
  455. X            case 'c':
  456. X                printf("Change line # %ld\n", CurrentLine);
  457. X                change(CurrentLine);
  458. X                changed = 'Y';
  459. X                break;
  460. X            case 'd':
  461. X                printf("Deleted line # %ld\n", CurrentLine);
  462. X                subtract(CurrentLine);
  463. X                changed = 'Y';
  464. X                break;
  465. X            case 'f':
  466. X            case '/':
  467. X                puts("Find string.");
  468. X                go_fish(CurrentLine);
  469. X                break;
  470. X            case 'g':
  471. X                puts("Global.");
  472. X                go_global(CurrentLine);
  473. X                changed = 'Y';
  474. X                break;
  475. X            case 'i':
  476. X                printf("Inserting before line %ld.\n", CurrentLine);
  477. X                insert(CurrentLine);
  478. X                changed = 'Y';
  479. X                break;
  480. X            case 'n': /* next occurence */
  481. X                puts("Next.");
  482. X                find('v');
  483. X                break;
  484. X            case 'p':
  485. X                puts("print.");
  486. X                printline(CurrentLine);
  487. X                break;
  488. X            case 'q':
  489. X                puts("quit.");
  490. X                if (WriteOnQuit == 'Y') {
  491. X                    if(saveem(file) == OK) {
  492. X                        return(OK);
  493. X                    } else {
  494. X                        fprintf(stderr, "%s: Write on quit set, but save failed.\n", Progname);
  495. X                        WriteOnQuit='N';
  496. X                        break;
  497. X                    }
  498. X                    
  499. X                }
  500. X                if (changed == 'Y') {
  501. X                    fputs("File changed, are you sure (y/n) ? ", stdout);
  502. X                    c=yesno();
  503. X                    if (c == 'N') 
  504. X                        break;
  505. X                }
  506. X                return(OK);
  507. X                break;
  508. X            case 's':
  509. X                puts("search/replace");
  510. X                srchrep(CurrentLine);
  511. X                changed = 'Y';
  512. X                break;
  513. X            case 'w':
  514. X                puts("Saveing.");
  515. X                saveem(file);
  516. X                changed = 'N';
  517. X                break;
  518. X            case '?':
  519. X                puts("Help.");
  520. X                help();
  521. X                break;
  522. X            default:
  523. X                puts("? - for help");
  524. X                break;
  525. X                
  526. X        }
  527. X    }
  528. X}
  529. END_OF_FILE
  530. if test 4136 -ne `wc -c <'command.c'`; then
  531.     echo shar: \"'command.c'\" unpacked with wrong size!
  532. fi
  533. # end of 'command.c'
  534. fi
  535. if test -f 'edit.c' -a "${1}" != "-c" ; then 
  536.   echo shar: Will not clobber existing file \"'edit.c'\"
  537. else
  538. echo shar: Extracting \"'edit.c'\" \(2656 characters\)
  539. sed "s/^X//" >'edit.c' <<'END_OF_FILE'
  540. X
  541. X/*
  542. X * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  543. X *  You are free to modify, hack, fold, spindle, or mutlate this code in
  544. X *  any maner provided you give credit where credit is due and don't pretend
  545. X *  you wrote it.
  546. X *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  547. X *  in copyright law that you will never ever forget.
  548. X */
  549. X#include "defs.h"
  550. X#include "externs.h"
  551. X
  552. append(number)
  553. long number;
  554. X{
  555. X    puts("Enter a single period on a blank line to return to the editor");
  556. X    for (;;number++) {
  557. X        getstring(buf, BUFSIZ, '\0');
  558. X        if (*buf == '.' && strlen(buf) == 1) 
  559. X            return(OK);
  560. X        add(buf, number);
  561. X    }
  562. X}
  563. X        
  564. change(number)
  565. long number;
  566. X{
  567. X    printf("Currently line %ld looks like:\n", number);
  568. X    printline(number);
  569. X    printf("Type the new line %ld\n", number);
  570. X    getstring(buf, BUFSIZ, '\0');
  571. X    if (*buf == '.' && strlen(buf) == 1)  {
  572. X        puts("Aborted.");
  573. X        return(!OK);
  574. X    }
  575. X    return(replace(number, buf));
  576. X}
  577. srchrep(number)
  578. long number;
  579. X{
  580. X    char old[81], new[81], c='\0';
  581. X    printf("Line %ld looks like :\n", number);
  582. X    printline(number);
  583. X    fputs("     Search string: ", stdout);
  584. X    if (getstring(old, 81, '\0') == NULL)
  585. X        return(!OK);
  586. X    fputs("Replacement string: ", stdout);
  587. X    if (getstring(new, 81, '\0') == NULL)
  588. X        return(!OK);
  589. X    while (c != 'N' && c != 'Y') {
  590. X        fputs("Global replacement? ", stdout);
  591. X        c=getchar();
  592. X        if (islower(c)) 
  593. X            c=toupper(c);
  594. X        if (c == '\n') 
  595. X            c='N';
  596. X        switch(c) {
  597. X            case 'N':
  598. X                puts("No.");
  599. X            break;
  600. X            case 'Y':
  601. X                puts("Yes.");
  602. X            break;
  603. X            case 'Q':
  604. X                return(!OK);
  605. X            break;
  606. X            default:
  607. X                fputs("\007<Y>es, <N>o or <Q>uit please.\n", stdout);
  608. X            break;
  609. X        }
  610. X    }
  611. X    srch_n_replace(number, old, new, c);
  612. X    printline(number);
  613. X    return(OK);
  614. X}
  615. go_fish(number)
  616. long number;
  617. X{
  618. X    char sstring[81];
  619. X    fputs("String to search for : ", stdout);
  620. X    if(getstring(sstring, 80, '\0') == NULL)
  621. X        return(!OK);
  622. X    if (setfind(number, sstring) == OK) 
  623. X        return(find('v') > 0L ? OK : !OK);
  624. X    return(!OK);
  625. X}
  626. go_global(number)
  627. long number;
  628. X{
  629. X    char old[81], new[81];
  630. X    fputs("     Search string: ", stdout);
  631. X    if (getstring(old, 80, '\0') == NULL)
  632. X        return(!OK);
  633. X    fputs("Replacement string: ", stdout);
  634. X    if (getstring(new, 80, '\0') == NULL)
  635. X        return(!OK);
  636. X    return(global_replace(number, old, new));
  637. X}
  638. global_replace(number, old, new)
  639. long number;
  640. char *old, *new;
  641. X{
  642. X    long line, count=0L;
  643. X    if (setfind(number, old) == OK) {
  644. X        while ((line=find('n')) > 0L)  {
  645. X            if (srch_n_replace(line, old, new, 'Y') == OK) 
  646. X                count++;
  647. X        }
  648. X        printf("Replaced \"%s\" with \"%s\" %ld times.\n",
  649. X            old, new, count);
  650. X
  651. X        return(count > 0L ? OK : !OK);
  652. X    }
  653. X    return(!OK);
  654. X}
  655. insert(number)
  656. long number;
  657. X{
  658. X    number--;
  659. X    return(append(number));
  660. X}
  661. END_OF_FILE
  662. if test 2656 -ne `wc -c <'edit.c'`; then
  663.     echo shar: \"'edit.c'\" unpacked with wrong size!
  664. fi
  665. # end of 'edit.c'
  666. fi
  667. if test -f 'find.c' -a "${1}" != "-c" ; then 
  668.   echo shar: Will not clobber existing file \"'find.c'\"
  669. else
  670. echo shar: Extracting \"'find.c'\" \(1349 characters\)
  671. sed "s/^X//" >'find.c' <<'END_OF_FILE'
  672. X
  673. X/*
  674. X * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  675. X *  You are free to modify, hack, fold, spindle, or mutlate this code in
  676. X *  any maner provided you give credit where credit is due and don't pretend
  677. X *  you wrote it.
  678. X *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  679. X *  in copyright law that you will never ever forget.
  680. X */
  681. X#include "defs.h"
  682. X#include "externs.h"
  683. X
  684. X#define __FILE__    "find.c"
  685. X
  686. long
  687. find(c)
  688. char c;
  689. X{
  690. X    if (find_work == (LINE *) NULL || find_line >= NumberLines) {
  691. X        puts(Eof);
  692. X        reset_find();
  693. X        return(-1L);
  694. X    }
  695. X    while (find_work != (LINE *) NULL) {
  696. X        if (strindex(find_work->text, find_string) != NULL) {
  697. X            CurrentLine=find_line;
  698. X            if (c == 'v') printline(CurrentLine);
  699. X            find_work = find_work -> next;
  700. X            find_line++;
  701. X            return(CurrentLine);
  702. X        }
  703. X        find_work = find_work -> next;
  704. X        find_line++;
  705. X    }
  706. X    puts(Eof);
  707. X    return(-1L);
  708. X}
  709. reset_find()
  710. X{
  711. X    find_work = l_start;
  712. X    find_line = 1L;
  713. X}
  714. setfind(number, string)
  715. long number;
  716. char *string;
  717. X{
  718. X    if (find_string != NULL)
  719. X        free(find_string);
  720. X    find_string = malloc(strlen(string) + 1);
  721. X    if (find_string == NULL) {
  722. X        fprintf(stderr, "%s: malloc(%d) failed\n", __FILE__,
  723. X                strlen(string));
  724. X        return(!OK);
  725. X    }
  726. X    strcpy(find_string, string);
  727. X    find_line = number;
  728. X    find_work = setline(find_line);
  729. X    return(find_work != (LINE *) NULL ? OK : !OK);
  730. X}
  731. END_OF_FILE
  732. if test 1349 -ne `wc -c <'find.c'`; then
  733.     echo shar: \"'find.c'\" unpacked with wrong size!
  734. fi
  735. # end of 'find.c'
  736. fi
  737. if test -f 'globals.c' -a "${1}" != "-c" ; then 
  738.   echo shar: Will not clobber existing file \"'globals.c'\"
  739. else
  740. echo shar: Extracting \"'globals.c'\" \(834 characters\)
  741. sed "s/^X//" >'globals.c' <<'END_OF_FILE'
  742. X
  743. X/*
  744. X * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  745. X *  You are free to modify, hack, fold, spindle, or mutlate this code in
  746. X *  any maner provided you give credit where credit is due and don't pretend
  747. X *  you wrote it.
  748. X *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  749. X *  in copyright law that you will never ever forget.
  750. X */
  751. X#include "defs.h"
  752. X
  753. XFILE    *EditFile;
  754. LINE    *current    = (LINE *) NULL;
  755. LINE    *find_work    = (LINE *) NULL;
  756. LINE    *l_end        = (LINE *) NULL;
  757. LINE    *l_start    = (LINE *) NULL; 
  758. char    *Bottom="Bottom of file.";
  759. char    *Eof="Search ending, bottom of file.";
  760. char    *Progname;
  761. char    *Top="Top of file.";
  762. char    *find_string = NULL;
  763. char    Dots        = 'N';
  764. char    WriteOnQuit    = 'N';
  765. char    buf[BUFSIZ];
  766. int    Debug;
  767. long    CurrentLine;
  768. long    NumberLines;
  769. long    find_line = 1L;
  770. char    *HelpName=WSEDHELP;
  771. END_OF_FILE
  772. if test 834 -ne `wc -c <'globals.c'`; then
  773.     echo shar: \"'globals.c'\" unpacked with wrong size!
  774. fi
  775. # end of 'globals.c'
  776. fi
  777. if test -f 'input.c' -a "${1}" != "-c" ; then 
  778.   echo shar: Will not clobber existing file \"'input.c'\"
  779. else
  780. echo shar: Extracting \"'input.c'\" \(1511 characters\)
  781. sed "s/^X//" >'input.c' <<'END_OF_FILE'
  782. X
  783. X/*
  784. X * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  785. X *  You are free to modify, hack, fold, spindle, or mutlate this code in
  786. X *  any maner provided you give credit where credit is due and don't pretend
  787. X *  you wrote it.
  788. X *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  789. X *  in copyright law that you will never ever forget.
  790. X */
  791. X#include "defs.h"
  792. X#include "externs.h"
  793. X
  794. long
  795. getlnum()
  796. X{
  797. X    getstring(buf, 10, '\0');
  798. X    return(makenum(buf));
  799. X}
  800. X
  801. char
  802. yesno()
  803. X{
  804. X    char c;
  805. X    for (;;) {
  806. X#ifdef MSDOS
  807. X        c=getch();
  808. X#else MSDOS
  809. X        c=getchar();
  810. X#endif MSDOS
  811. X        if (islower(c))
  812. X            c=toupper(c);
  813. X        switch (c) {
  814. X            case 'Y':
  815. X                puts("Yes.");
  816. X                return(c);
  817. X            break;
  818. X            case 'N':
  819. X                puts("No.");
  820. X                return(c);
  821. X            break;
  822. X            default:
  823. X                puts("<Y>es or <N>o please.");
  824. X            break;
  825. X        }
  826. X    }
  827. X}
  828. X/*
  829. X *    This routine gets a string..
  830. X *
  831. X */
  832. char *
  833. getstring(str, len, first)
  834. char    *str;
  835. int    len;
  836. char    first;
  837. X{
  838. X    char *p, c;
  839. X    p = str;
  840. X    if (first != '\0')  {
  841. X        *(p++) = first;
  842. X        putchar(first);
  843. X    }        
  844. X    for ( ;; ) {
  845. X#ifdef MSDOS
  846. X        c = getch();
  847. X#else
  848. X        c = getchar();
  849. X#endif MSDOS
  850. X        switch(c) {
  851. X            case '\b': {
  852. X                if (p > str) {
  853. X                    *p='\0';
  854. X                    fputs("\010 \010", stdout);
  855. X                    *(p--)='\0';
  856. X                } else {
  857. X                    putchar('\007');
  858. X                    }
  859. X                }
  860. X                break;
  861. X            case '\n':
  862. X            case '\r': {
  863. X                *p='\0';
  864. X                putchar('\n');
  865. X                return(*str != '\0' ? str : NULL);
  866. X                } break;
  867. X            default: {
  868. X                if (p < str+len) {
  869. X                    *(p++) = c;
  870. X                    putchar(c);
  871. X                } else { 
  872. X                    putchar('\007');
  873. X                }
  874. X            } break;
  875. X        }
  876. X    }
  877. X}
  878. END_OF_FILE
  879. if test 1511 -ne `wc -c <'input.c'`; then
  880.     echo shar: \"'input.c'\" unpacked with wrong size!
  881. fi
  882. # end of 'input.c'
  883. fi
  884. if test -f 'main.c' -a "${1}" != "-c" ; then 
  885.   echo shar: Will not clobber existing file \"'main.c'\"
  886. else
  887. echo shar: Extracting \"'main.c'\" \(2419 characters\)
  888. sed "s/^X//" >'main.c' <<'END_OF_FILE'
  889. X
  890. X/*
  891. X * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  892. X *  You are free to modify, hack, fold, spindle, or mutlate this code in
  893. X *  any maner provided you give credit where credit is due and don't pretend
  894. X *  you wrote it.
  895. X *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  896. X *  in copyright law that you will never ever forget.
  897. X */
  898. X#include "defs.h"
  899. X#include "externs.h"
  900. X
  901. main(argc, argv)
  902. int argc;
  903. char **argv;
  904. X{
  905. X    int c;
  906. X    char start_line[80];
  907. X    extern char *optarg;
  908. X    extern int optind, opterr;
  909. X    opterr=1;
  910. X    Progname = *argv;
  911. X#ifndef MSDOS
  912. X    savetty();
  913. X    initscr();
  914. X#endif MSDOS
  915. X    signal(SIGINT, SIG_IGN);
  916. X    while ((c=getopt(argc, argv, "Dwa:")) != EOF) {
  917. X        switch (c) {
  918. X        case 'D': Debug = 1;            break;
  919. X        case 'a': strcpy(start_line,optarg);    break;
  920. X        case 'w': WriteOnQuit='Y';        break;
  921. X        }
  922. X    }
  923. X    if (Debug) printf("extra args %d\n", optind);
  924. X    if (argc < 2) {
  925. X        fprintf(stderr, "%s: usage: %s [options] file [ file file]\n",
  926. X                Progname, Progname);
  927. X        exit(-1);
  928. X    }
  929. X    for (;optind < argc; optind++) {
  930. X        errno=0;
  931. X        edit(argv[optind], start_line);
  932. X        *start_line = '\0';
  933. X    }
  934. X    resetty();
  935. X    exit(errno);
  936. X}
  937. X
  938. edit(file, sline)
  939. char *file;
  940. char *sline;
  941. X{
  942. X    struct stat stbuff, *s;
  943. X    char c;
  944. X    int new=!OK;
  945. X    s=(struct stat *) &stbuff;
  946. X    clear_stuff();
  947. X    noecho();
  948. X    One_Char();
  949. X    if ((EditFile=fopen(file, "r")) == (FILE *) NULL) {
  950. X        if (errno == ENOENT) {
  951. X            printf("File %s doesn't exist, create (y/n) ? ",
  952. X                file);
  953. X            c=yesno();
  954. X            switch(c) {
  955. X                case 'Y':
  956. X                    close(creat(file, 0666));
  957. X                    if ((EditFile=fopen(file, "r")) == (FILE *) NULL) {
  958. X                        /* give up... */
  959. X                        fprintf(stderr, "%s: could not create %s\n", Progname, file);
  960. X                        return(!OK);
  961. X                    }
  962. X                    new=OK;
  963. X                    break;
  964. X                case 'N':
  965. X                default:
  966. X                    return(OK);
  967. X                    break;    
  968. X            }
  969. X        } else {
  970. X        fprintf(stderr, "%s: Could not read %s",
  971. X            Progname, file);
  972. X            perror("");
  973. X            return(!OK);
  974. X        }
  975. X    }
  976. X    if (fstat(fileno(EditFile), s) < 0) {
  977. X        fprintf(stderr, "%s: fstat(%d) failed",
  978. X            Progname, fileno(EditFile));
  979. X            perror("");
  980. X            return(!OK);
  981. X        }
  982. X    if (s->st_size > BEGINDOTS)
  983. X        Dots = 'Y';
  984. X    if (new != OK && s->st_size > 0L)  {
  985. X        if (loadem(EditFile, 0L) > 0L) {
  986. X            printf("File: \"%s\"   lines=%ld, charicters=%ld\n",
  987. X                file, NumberLines, s->st_size);
  988. X            fclose(EditFile);
  989. X            command(file, sline);
  990. X        }
  991. X    } else {
  992. X        printf("File: \"%s\" is new, begin entering new text\n", file);
  993. X        append(0L);
  994. X        command(file, "\0");
  995. X    }
  996. X    return(OK);
  997. X}
  998. END_OF_FILE
  999. if test 2419 -ne `wc -c <'main.c'`; then
  1000.     echo shar: \"'main.c'\" unpacked with wrong size!
  1001. fi
  1002. # end of 'main.c'
  1003. fi
  1004. if test -f 'mem.c' -a "${1}" != "-c" ; then 
  1005.   echo shar: Will not clobber existing file \"'mem.c'\"
  1006. else
  1007. echo shar: Extracting \"'mem.c'\" \(5810 characters\)
  1008. sed "s/^X//" >'mem.c' <<'END_OF_FILE'
  1009. X    
  1010. X/*
  1011. X * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  1012. X *  You are free to modify, hack, fold, spindle, or mutlate this code in
  1013. X *  any maner provided you give credit where credit is due and don't pretend
  1014. X *  you wrote it.
  1015. X *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  1016. X *  in copyright law that you will never ever forget.
  1017. X */
  1018. X#include "defs.h"
  1019. X#include "externs.h"
  1020. X
  1021. X#define __FILE__    "mem.c"
  1022. X
  1023. clear_stuff()
  1024. X{
  1025. X    LINE *temp, *next;
  1026. X    if (l_start != (LINE *) NULL) {
  1027. X        /* something inside, clear 'em out */
  1028. X        for (temp = l_end; temp != l_start ;) {
  1029. X            next = temp->previous;
  1030. X            free(temp);
  1031. X            temp = next;
  1032. X        }
  1033. X    }
  1034. X    l_start = (LINE *) malloc(sizeof(LINE) + 2);
  1035. X    l_start -> previous     = (LINE *) NULL;
  1036. X    l_start -> next        = (LINE *) NULL;
  1037. X    l_end             = l_start;
  1038. X    current            = l_start;
  1039. X    CurrentLine        = 0L;
  1040. X    NumberLines        = 0L;
  1041. X}
  1042. long
  1043. loadem(inputfile, place)
  1044. XFILE *inputfile;
  1045. long place;
  1046. X{
  1047. X    while ((fgets(buf, BUFSIZ, inputfile)) != NULL) {
  1048. X        if(add(buf, place++) != OK) {
  1049. X            fprintf(stderr, "%s:%d loadem() add() failure\n", 
  1050. X                __FILE__, __LINE__);
  1051. X            return(!OK);
  1052. X        }
  1053. X        if (Dots == 'Y' || Debug) {
  1054. X            putchar('.');
  1055. X            fflush(stdout);
  1056. X        }
  1057. X    }
  1058. X    putchar('\n');
  1059. X    return(NumberLines);
  1060. X}
  1061. LINE *
  1062. setline(number)
  1063. long number;
  1064. X{
  1065. X    LINE *tmp;
  1066. X    tmp=getline(number);
  1067. X    if (tmp != (LINE *) NULL)  {
  1068. X        CurrentLine = number;
  1069. X        current = tmp;
  1070. X    }
  1071. X
  1072. X    return(tmp);
  1073. X}
  1074. LINE *
  1075. getline(number)
  1076. long number;
  1077. X{
  1078. X    LINE *inc;
  1079. X    long i;
  1080. X    if (number > NumberLines) {
  1081. X        printf("%s-%s: getline(%ld) > NumberLines == %ld\n",
  1082. X            Progname, __FILE__, number, NumberLines);
  1083. X        return((LINE *)NULL);
  1084. X    }
  1085. X    if (number == 0L) 
  1086. X        return(l_start);
  1087. X    for (i=1L, inc=l_start; i<number ; i++, inc=inc->next);
  1088. X    return(inc);
  1089. X}
  1090. printline(number)
  1091. long number;
  1092. X{
  1093. X    LINE *tmp;
  1094. X    if ((tmp=setline(number)) != (LINE *) NULL) {
  1095. X        fputs(tmp->text, stdout);
  1096. X        fflush(stdout);
  1097. X        return(OK);
  1098. X    }
  1099. X    fprintf(stderr, "%s: printline(%ld) Bad line number\n", __FILE__, number);
  1100. X    fflush(stderr);
  1101. X    return(!OK);
  1102. X}
  1103. X
  1104. X
  1105. X
  1106. add(buf, number)
  1107. char *buf;
  1108. long number;
  1109. X{
  1110. X    LINE *new, *temp;
  1111. X    if (Debug) printf("add(%ld)\n", number);
  1112. X    new = (LINE *) malloc(sizeof(LINE) + strlen(buf));
  1113. X    if (number > 0L) {
  1114. X        temp=getline(number);
  1115. X        if (temp == (LINE *) NULL)  {
  1116. X            fprintf(stderr, "%s: add(%ld) bad line number\n",
  1117. X                __FILE__, number);
  1118. X            return(!OK);
  1119. X        }
  1120. X        new -> previous = temp;
  1121. X        if (temp->next != (LINE *) NULL)  {
  1122. X            temp->next->previous = new;
  1123. X            new -> next = temp->next;
  1124. X        } else {
  1125. X            new->next = (LINE *) NULL;
  1126. X            l_end = new;
  1127. X        }
  1128. X        temp -> next = new;
  1129. X    } else {
  1130. X        new -> previous = (LINE *) NULL;
  1131. X        if (NumberLines < 1L) {
  1132. X            new -> next = (LINE *) NULL;
  1133. X            l_end = new;
  1134. X        } else 
  1135. X            new -> next = l_end;
  1136. X
  1137. X        /* Now, blow away anything nasty, still hanging around */
  1138. X        if (l_start != (LINE *) NULL)
  1139. X            free(l_start); 
  1140. X
  1141. X        l_start = new;
  1142. X        current = new;
  1143. X    }
  1144. X    /* make sure line has a newline on the end.. */
  1145. X    if (buf[strlen(buf)-1] != '\n')
  1146. X        strcat(buf, "\n");
  1147. X    strcpy(new->text, buf);
  1148. X    NumberLines++;
  1149. X    current=new;
  1150. X    CurrentLine=NumberLines;
  1151. X    return(OK);
  1152. X}
  1153. subtract(number)
  1154. long number;
  1155. X{
  1156. X    LINE *tmp;
  1157. X    tmp = getline(number);
  1158. X    if (tmp == (LINE *)NULL) {
  1159. X        fprintf(stderr, "%s: subtract(%ld) bad line number\n", 
  1160. X            __FILE__, number);
  1161. X        return(!OK);
  1162. X    }
  1163. X    if (l_end == tmp) {
  1164. X        l_end = l_end -> previous;
  1165. X    }
  1166. X    if (tmp -> previous != (LINE *) NULL) 
  1167. X        tmp -> previous -> next = tmp -> next; 
  1168. X     else {
  1169. X        if (tmp -> next != (LINE *) NULL) {
  1170. X            tmp -> next -> previous = (LINE *) NULL;
  1171. X            l_start = tmp -> next;
  1172. X        }
  1173. X    }
  1174. X
  1175. X    if (tmp -> next != (LINE *) NULL)
  1176. X        tmp -> next -> previous  = tmp -> previous;
  1177. X     else {
  1178. X        if (tmp -> previous != (LINE *) NULL) {
  1179. X            tmp -> previous -> next = (LINE *) NULL;
  1180. X            l_end = tmp -> previous;
  1181. X        }
  1182. X    }
  1183. X    if (NumberLines-- > 1L)
  1184. X        free(tmp);
  1185. X    current=setline(number < NumberLines ? number : NumberLines);
  1186. X    return(current != (LINE *) NULL ? OK : !OK);
  1187. X}
  1188. X    
  1189. replace(number, buf)
  1190. char *buf;
  1191. long number;
  1192. X{
  1193. X    LINE *old, *new;
  1194. X    old=getline(number);
  1195. X    if (old == (LINE *) NULL)  {
  1196. X        fprintf(stderr, "%s: replace(%ld) bad line number\n", __FILE__, number);
  1197. X        return(!OK);
  1198. X    }
  1199. X    new = (LINE *) malloc(sizeof(LINE) + strlen(buf));
  1200. X    new -> previous        = old -> previous;
  1201. X    new -> next        = old -> next;
  1202. X    if (new -> previous != (LINE *) NULL)  
  1203. X        new -> previous -> next = new;
  1204. X    else 
  1205. X        l_start = new;
  1206. X
  1207. X    if (new -> next != (LINE *) NULL)  
  1208. X        new -> next -> previous = new;
  1209. X    else 
  1210. X        l_end = new;
  1211. X
  1212. X    if (STRCHR(buf, '\n') == NULL)
  1213. X        strcat(buf, "\n");
  1214. X    strcpy(new->text, buf);
  1215. X    free(old);
  1216. X    current=setline(number);
  1217. X    return(current != (LINE *) NULL ? OK : !OK );
  1218. X}
  1219. srch_n_replace(number, old_str, new_str, glob)
  1220. long number;
  1221. char *old_str, *new_str;
  1222. char glob;
  1223. X{
  1224. X    LINE *work;
  1225. X    char *p, *b, *buff;
  1226. X    int len_old, cnt=0;
  1227. X    work = getline(number);
  1228. X    if (work == (LINE *) NULL) {
  1229. X        fprintf(stderr, "%s: srch_n_replace(%ld) bad line number\n",
  1230. X            __FILE__, number);
  1231. X        return(!OK);
  1232. X    }
  1233. X    len_old = strlen(old_str);
  1234. X    buff = malloc(MAXREPLACE);
  1235. X    if (buff == NULL)
  1236. X        return(!OK);
  1237. X    p=work->text;
  1238. X    b=buff;
  1239. X    do {
  1240. X        cnt++;
  1241. X        if (*p == *old_str)  {
  1242. X            if (!strncmp(p, old_str, len_old)) {
  1243. X                p += (len_old-1); /* advance past string */
  1244. X                b = strappend(b, new_str);
  1245. X                if (glob == 'N')  {
  1246. X                    p++;
  1247. X                    strcat(b, p);
  1248. X                    break;
  1249. X                }
  1250. X            } else
  1251. X            *(b++) = *p;
  1252. X        } else 
  1253. X            *(b++) = *p;
  1254. X    } while ((*(p++) != '\0') && cnt < MAXREPLACE);
  1255. X    replace(number, buff);
  1256. X    free(buff);
  1257. X    return(OK);
  1258. X}
  1259. saveem(file)
  1260. char *file;
  1261. X{
  1262. X    LINE *work;
  1263. X    int out;
  1264. X    long count=0L;
  1265. X    out = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  1266. X    if (out < 0) {
  1267. X        fprintf(stderr, "%s: Could not open \"%s\" for writing",
  1268. X            Progname, file);
  1269. X        perror("");
  1270. X        return(!OK);
  1271. X    }
  1272. X    work = l_start;
  1273. X    while (work != (LINE *) NULL && count < NumberLines)  {
  1274. X        count++;
  1275. X        write(out, work->text, strlen(work->text));
  1276. X        work = work-> next;
  1277. X        if (WriteOnQuit != 'Y') putchar('.');
  1278. X    }
  1279. X    close(out);
  1280. X    putchar('\n');
  1281. X    return(OK);
  1282. X}
  1283. END_OF_FILE
  1284. if test 5810 -ne `wc -c <'mem.c'`; then
  1285.     echo shar: \"'mem.c'\" unpacked with wrong size!
  1286. fi
  1287. # end of 'mem.c'
  1288. fi
  1289. if test -f 'multi.c' -a "${1}" != "-c" ; then 
  1290.   echo shar: Will not clobber existing file \"'multi.c'\"
  1291. else
  1292. echo shar: Extracting \"'multi.c'\" \(1593 characters\)
  1293. sed "s/^X//" >'multi.c' <<'END_OF_FILE'
  1294. X
  1295. X/*
  1296. X * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  1297. X *  You are free to modify, hack, fold, spindle, or mutlate this code in
  1298. X *  any maner provided you give credit where credit is due and don't pretend
  1299. X *  you wrote it.
  1300. X *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  1301. X *  in copyright law that you will never ever forget.
  1302. X */
  1303. X#include "defs.h"
  1304. X#include "externs.h"
  1305. X
  1306. X#define RANGE(x)    (x > 0 && x <= NumberLines)
  1307. static char *Start="Starting line number ";
  1308. static char *End=  "  Ending line number ";
  1309. multi_change()
  1310. X{
  1311. X    long start, end, count;
  1312. X    char *string="for changes :";
  1313. X    fputs(Start, stdout);
  1314. X    fputs(string, stdout);
  1315. X    start=getlnum();
  1316. X    if (!RANGE(start)) 
  1317. X        return(!OK);
  1318. X    fputs(End, stdout);
  1319. X    fputs(string, stdout);
  1320. X    end=getlnum();
  1321. X    if (!RANGE(end))
  1322. X        return(!OK);
  1323. X    for(count = start ; count <= end ; count++) 
  1324. X        change(count);
  1325. X    return(OK);
  1326. X}
  1327. multi_delete()
  1328. X{
  1329. X    long start, end, count;
  1330. X    char *string="to delete : ";
  1331. X    fputs(Start, stdout);
  1332. X    fputs(string, stdout);
  1333. X    start=getlnum();
  1334. X    if (!RANGE(start)) 
  1335. X        return(!OK);
  1336. X    fputs(End, stdout);
  1337. X    fputs(string, stdout);
  1338. X    end=getlnum();
  1339. X    if (!RANGE(end))
  1340. X        return(!OK);
  1341. X    for(count = end ; count >= start ; count--) 
  1342. X        subtract(count);
  1343. X    return(OK);
  1344. X}
  1345. multi_print()
  1346. X{
  1347. X    long start, end, count;
  1348. X    char *string="to be printed : ";
  1349. X    fputs(Start, stdout);
  1350. X    fputs(string, stdout);
  1351. X    start=getlnum();
  1352. X    if (!RANGE(start)) 
  1353. X        return(!OK);
  1354. X    fputs(End, stdout);
  1355. X    fputs(string, stdout);
  1356. X    end=getlnum();
  1357. X    if (!RANGE(end))
  1358. X        return(!OK);
  1359. X    for(count = start ; count <= end ; count++) 
  1360. X        printline(count);
  1361. X    return(OK);
  1362. X}
  1363. END_OF_FILE
  1364. if test 1593 -ne `wc -c <'multi.c'`; then
  1365.     echo shar: \"'multi.c'\" unpacked with wrong size!
  1366. fi
  1367. # end of 'multi.c'
  1368. fi
  1369. if test -f 'stuff.c' -a "${1}" != "-c" ; then 
  1370.   echo shar: Will not clobber existing file \"'stuff.c'\"
  1371. else
  1372. echo shar: Extracting \"'stuff.c'\" \(1773 characters\)
  1373. sed "s/^X//" >'stuff.c' <<'END_OF_FILE'
  1374. X/*
  1375. X * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  1376. X *  You are free to modify, hack, fold, spindle, or mutlate this code in
  1377. X *  any maner provided you give credit where credit is due and don't pretend
  1378. X *  you wrote it.
  1379. X *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  1380. X *  in copyright law that you will never ever forget.
  1381. X */
  1382. X#include "defs.h"    /* just for the #define of a NULL */
  1383. X#include "externs.h" /* for the strings things. */
  1384. X
  1385. X/* append  s2 unto s1, returning a pointer to the new "end" of s1 */
  1386. char *
  1387. strappend(s1, s2)
  1388. char *s1, *s2;
  1389. X{
  1390. X    register char *p, *r;
  1391. X    p = s1;
  1392. X    r = s2;
  1393. X    do {
  1394. X        *(p++) = *r;
  1395. X    } while ( *(r++) != '\0');
  1396. X    p--;
  1397. X    return(p);
  1398. X}
  1399. X/* return a pointer to the first occurence of s2 in s1 otherwise NULL */
  1400. char *
  1401. strindex(s1, s2)
  1402. char *s1, *s2;
  1403. X{
  1404. X    register char *p, *s;
  1405. X    register int len;
  1406. X    p=s1;
  1407. X    len = strlen(s2);
  1408. X    /* quick test to blow away short lines */
  1409. X    if (len > strlen(s1))
  1410. X        return(NULL);
  1411. X    while ((s=STRCHR(p, *s2)) != NULL) {
  1412. X        if (!strncmp(s, s2, len))  {
  1413. X            return(s);
  1414. X        }
  1415. X        p= (++s);
  1416. X    }
  1417. X    return(NULL);
  1418. X}
  1419. long
  1420. makenum(buf)
  1421. char *buf;
  1422. X{
  1423. X    switch (*buf) {
  1424. X        case '\0':
  1425. X            return(-1L);
  1426. X        break;
  1427. X        case '$':
  1428. X            return(NumberLines);
  1429. X        break;
  1430. X        case '^':
  1431. X            return(1L);
  1432. X        break;
  1433. X        case '0':
  1434. X        case '1':
  1435. X        case '2':
  1436. X        case '3':
  1437. X        case '4':
  1438. X        case '5':
  1439. X        case '6':
  1440. X        case '7':
  1441. X        case '8':
  1442. X        case '9':
  1443. X            return(atol(buf) > 1L ? atol(buf) : 1L);
  1444. X        break;
  1445. X        default:
  1446. X            return(-1L);
  1447. X    }
  1448. X    return(-1L);
  1449. X}
  1450. help()
  1451. X{
  1452. X    register int input, amount;
  1453. X    if ((input = open (HelpName, O_RDONLY)) < 0) {
  1454. X        fprintf(stderr, "%s: Could not open file \"%s\"",
  1455. X            Progname, HelpName);
  1456. X        perror("");
  1457. X        return(!OK);
  1458. X    }
  1459. X    while((amount=read(input, buf, BUFSIZ)) > 0)
  1460. X        write(1, buf, amount);
  1461. X    close(input);
  1462. X    return(OK);
  1463. X}
  1464. END_OF_FILE
  1465. if test 1773 -ne `wc -c <'stuff.c'`; then
  1466.     echo shar: \"'stuff.c'\" unpacked with wrong size!
  1467. fi
  1468. # end of 'stuff.c'
  1469. fi
  1470. echo shar: End of archive 1 \(of 1\).
  1471. cp /dev/null ark1isdone
  1472. MISSING=""
  1473. for I in 1 ; do
  1474.     if test ! -f ark${I}isdone ; then
  1475.     MISSING="${MISSING} ${I}"
  1476.     fi
  1477. done
  1478. if test "${MISSING}" = "" ; then
  1479.     echo You have the archive.
  1480.     echo "Now read the README file and edit the Makefile for your system"
  1481.     rm -f ark[1-9]isdone
  1482. else
  1483.     echo You still need to unpack the following archives:
  1484.     echo "        " ${MISSING}
  1485. fi
  1486. ##  End of shell archive.
  1487. exit 0
  1488.